-- VERSION 1.1
-- CREATED BY AJAX
-- DO NOT REDISTRIBUTE
local function AddToChat(msg)
	local col1 = Color(msg:ReadShort(), msg:ReadShort(), msg:ReadShort())

	local name = msg:ReadString()
	local ply = msg:ReadEntity()

	if name == "" then name = ply.DarkRPVars.rpname end

	local col2 = Color(msg:ReadShort(), msg:ReadShort(), msg:ReadShort())

local text = msg:ReadString()
	local rank_str, rank_col, bracket_col
	if ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("owner") then
        rank_str = "Owner"
        rank_col = Color( 205, 92, 92 )
        bracket_col = Color( 50, 205, 50)
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("headadmin") then
        rank_str = "HeadAdmin"
        rank_col = Color( 0, 0, 160 )
        bracket_col = Color( 50, 205, 50 )	
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("moderator") then
        rank_str = "Mod"
        rank_col = Color( 51, 204, 255 )
        bracket_col = Color( 50, 205, 50 )
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("respected") then
        rank_str = "Respected"
        rank_col = Color( 51, 204, 255 )
        bracket_col = Color( 50, 205, 50 )
	elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("superadmin") then
        rank_str = "SA"
        rank_col = Color( 255, 69, 0 )
        bracket_col = Color( 50, 205, 50 )
    elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("admin") then
        rank_str = "Admin"
        rank_col = Color( 128, 255, 0 )
        bracket_col = Color( 50, 205, 50 )
    elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("vip") then
        rank_str = "VIP"
        rank_col = Color( 51, 204, 255 )
        bracket_col = Color( 50, 205, 50  )
    else
        rank_str = ""
        rank_col = Color( 255, 255, 255 )
    end
    if text and text ~= "" then
        chat.AddText(col1, name, bracket_col, bracket_col  and " [" or "", rank_col, rank_str, bracket_col, bracket_col and "] " or "", col2, ": "..text)
        if ValidEntity(ply) then
            hook.Call("OnPlayerChat", nil, ply, text, false, ply:Alive())
        end
    else
        chat.AddText(col1, name)
        hook.Call("ChatText", nil, "0", name, name, "none")
    end
    chat.PlaySound()
end
usermessage.Hook( "DarkRP_Chat", AddToChat )

-- To add more custom groups use this format
  --  elseif ply:IsValid() and ply:IsPlayer() and ply:IsUserGroup("GroupName") then
     --   rank_str = "Tags"
       -- rank_col = Color( 128, 255, 0 ) RED-GREEN-BLUE
       -- bracket_col = Color( 50, 205, 50 ) RED-GREEN-BLUE